{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# MTH 9879 Market Microstructure Models, Spring 2015 \n",
    "\n",
    "## Lecture 9: Optimal trading strategies: Almgren-Chriss\n",
    "\n",
    "Tai-Ho Wang    \n",
    "Department of Mathematics   \n",
    "  \n",
    "  \n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2014/09/BCCUNYstacked_BLK.jpg\" align = \"center\" width=160></h2>  \n",
    "\n",
    "$$\n",
    "\\newcommand{\\bea}{\\begin{eqnarray}}\n",
    "\\newcommand{\\eea}{\\end{eqnarray}}\n",
    "\\newcommand{\\supp}{\\mathrm{supp}}\n",
    "\\newcommand{\\F}{\\mathcal{F} }\n",
    "\\newcommand{\\cF}{\\mathcal{F} }\n",
    "\\newcommand{\\cG}{\\mathcal{G} }\n",
    "\\newcommand{\\E}{\\mathbb{E} }\n",
    "\\newcommand{\\Eof}[1]{\\mathbb{E}\\left[ #1 \\right]}\n",
    "\\def\\Cov{{ \\mbox{Cov} }}\n",
    "\\def\\Var{{ \\mbox{Var} }}\n",
    "\\newcommand{\\1}{\\mathbf{1} }\n",
    "\\newcommand{\\p}{\\partial}\n",
    "\\newcommand{\\PP}{\\mathbb{P} }\n",
    "\\newcommand{\\Pof}[1]{\\mathbb{P}\\left[ #1 \\right]}\n",
    "\\newcommand{\\QQ}{\\mathbb{Q} }\n",
    "\\newcommand{\\R}{\\mathbb{R} }\n",
    "\\newcommand{\\DD}{\\mathbb{D} }\n",
    "\\newcommand{\\HH}{\\mathbb{H} }\n",
    "\\newcommand{\\spn}{\\mathrm{span} }\n",
    "\\newcommand{\\cov}{\\mathrm{cov} }\n",
    "\\newcommand{\\HS}{\\mathcal{L}_{\\mathrm{HS}} }\n",
    "\\newcommand{\\Hess}{\\mathrm{Hess} }\n",
    "\\newcommand{\\trace}{\\mathrm{trace} }\n",
    "\\newcommand{\\LL}{\\mathcal{L} }\n",
    "\\newcommand{\\s}{\\mathcal{S} }\n",
    "\\newcommand{\\ee}{\\mathcal{E} }\n",
    "\\newcommand{\\ff}{\\mathcal{F} }\n",
    "\\newcommand{\\hh}{\\mathcal{H} }\n",
    "\\newcommand{\\bb}{\\mathcal{B} }\n",
    "\\newcommand{\\dd}{\\mathcal{D} }\n",
    "\\newcommand{\\g}{\\mathcal{G} }\n",
    "\\newcommand{\\half}{\\frac{1}{2} }\n",
    "\\newcommand{\\T}{\\mathcal{T} }\n",
    "\\newcommand{\\bit}{\\begin{itemize}}\n",
    "\\newcommand{\\eit}{\\end{itemize}}\n",
    "\\newcommand{\\beq}{\\begin{equation}}\n",
    "\\newcommand{\\eeq}{\\end{equation}}\n",
    "\\newcommand{\\tr}{\\mbox{tr}}\n",
    "\\newcommand{\\underbar}{\\underline}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Outline of Lecture 9\n",
    "\n",
    "-   The Euler-Lagrange equation\n",
    "\n",
    "-   The Hamilton-Jacobi-Bellman equation\n",
    "\n",
    "-   The Almgren-Chriss optimal liquidation strategy\n",
    "\n",
    "-   Dependence on dynamical assumptions: ABM vs GBM\n",
    "\n",
    "-   Almgren (2005)\n",
    "\n",
    "-   Optimal portfolio liquidation with a dark pool\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Overview of execution algorithm design\n",
    "\n",
    "Typically, an execution algorithm has three layers:\n",
    "\n",
    "-   The macrotrader\n",
    "\n",
    "    -   This highest level layer decides how to slice the order: when\n",
    "        the algorithm should trade, in what size and for roughly how\n",
    "        long.\n",
    "\n",
    "\n",
    "-   The microtrader\n",
    "\n",
    "    -   Given a slice of the order to trade (a child order), this level\n",
    "        decides whether to place market or limit orders and at what\n",
    "        price level(s).\n",
    "\n",
    "\n",
    "-   The smart order router\n",
    "\n",
    "    -   Given a limit or market order, which venue should this order be\n",
    "        sent to?\n",
    "\n",
    "In this lecture, we are concerned with the highest level of the\n",
    "algorithm: How to slice the order.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Statement of the problem\n",
    "\n",
    "-   <span> Given a model for the evolution of the stock price, we would\n",
    "    like to find an optimal strategy for trading stock, the strategy\n",
    "    that minimizes some cost function over all permissible strategies.\n",
    "    </span>\n",
    "\n",
    "    -   <span>We will specialize to the case of stock liquidation where\n",
    "        the initial position $x_0=X$ and the final position\n",
    "        $x_T=0$.</span>\n",
    "\n",
    "\n",
    "-   <span>A <span>*static*</span> strategy is one determined in advance\n",
    "    of trading.</span>\n",
    "\n",
    "\n",
    "-   <span>A <span>*dynamic*</span> strategy is one that depends on the\n",
    "    state of the market during execution of the order, *i.e.* on the\n",
    "    stock price.</span>\n",
    "\n",
    "    -   <span>Delta-hedging is an example of a dynamic strategy. VWAP is\n",
    "        an example of a static strategy.</span>\n",
    "\n",
    "\n",
    "-   It will turn out, surprisingly, that in many models, a\n",
    "    statically optimal strategy is also dynamically optimal.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Euler-Lagrange equation\n",
    "\n",
    "Suppose that the strategy $x_t$ minimizes the cost functional\n",
    "\n",
    "$$\\mathcal{C} [x,\\dot x]=\\int_0^T\\,L(t,x_t,\\dot x_t)\\,dt$$ \n",
    "\n",
    "with boundary conditions $x_0=0$, $x_T=X$ (assume we are acquiring $X$ shares). \n",
    "\n",
    "Let $\\varphi$ be a perturbation with $\\varphi(0)=\\varphi(T)=0$.\n",
    "The first order criterion for optimal strategy (if there exists one) is\n",
    "\n",
    "$$\\left.\\frac{d}{d\\epsilon}\\right|_{\\epsilon=0}C[x+\\epsilon\\,\\varphi,\\dot x + \\epsilon\\,\\dot \\varphi]=0.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Euler-Lagrange equation\n",
    "\n",
    "Computing this derivative explicitly (suppressing explicit dependence on\n",
    "$t$),\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\left.\\frac{d}{d\\epsilon}\\right|_{\\epsilon=0}C &=& \\int_0^T\\,\\left\\{\\frac{\\partial L}{\\partial x}\\,\\varphi+\\frac{\\partial L}{\\partial\\dot x}\\,\\dot \\varphi\\right\\}\\,dt \\\\\n",
    "&=& \\int_0^T\\,\\left\\{\\frac{\\partial L}{\\partial x}\\,\\varphi - \\int_0^T \\frac{d}{dt}\\frac{\\partial L}{\\partial\\dot x}\\,\\dot \\varphi\\right\\}\\,dt + \\left.\\frac{\\partial L}{\\partial\\dot x}\\,\\varphi\\right|_{t=0}^T  \\quad (\\mbox{by applying integration by partys}) \\\\\n",
    "&=& \\int_0^T\\,\\left\\{\\frac{\\partial L}{\\partial x}-\\frac{\\partial}{\\partial t}\\frac{\\partial L}{\\partial\\dot x}\\right\\}\\,\\varphi\\,dt \\quad (\\mbox{since } \\varphi(0) = \\varphi(T) = 0)\n",
    "\\end{eqnarray*}\n",
    "\n",
    "Since, this must hold for any perturbation $\\varphi$ with\n",
    "$\\varphi(0)=\\varphi(T)=0$, we deduce\n",
    "\n",
    "<font color=\"blue\">\n",
    "####<span>The Euler-Lagrange equation</span>\n",
    "$$\\frac{\\partial}{\\partial t}\\,\\left(\\frac{\\partial L}{\\partial {\\dot x} }\\right)-\\frac{\\partial L}{\\partial {x} }=0$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Stochastic control problem\n",
    "\n",
    "A stochastic control problem is a control problem which aims to minimize certain expected costs among all admissible controls. <br>\n",
    "Specifically, consider\n",
    "\n",
    "$$\n",
    "  \\max_{v\\in\\mathcal G[0,T]} \\E\\left[g(X^{(v)}_T) + \\int_0^T h(s,X^{(v)}_s,v_s) ds \\right]\n",
    "$$\n",
    "\n",
    "where\n",
    "\n",
    "* $g$ is referred to as the *terminal cost* and $h$ is the *running cost*\n",
    "\n",
    "\n",
    "* the state variable $X^{(v)}_t$ is driven by the controlled SDE\n",
    "\n",
    "    $$\n",
    "      dX^{(v)}_t = \\mu( t,X^{(v)}_t, v_t) dt + \\sigma(t,X^{(v)}_t, v_t) dW_t.\n",
    "    $$\n",
    "    \n",
    "\n",
    "* $\\mathcal G[0,T]$ is the collection of admissible controls in the time interval $[0,T]$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Bellman’s principle of optimality\n",
    "\n",
    "“An optimal policy has the property that whatever the initial state and\n",
    "initial decision are, the remaining decisions must constitute an optimal\n",
    "policy with regard to the state resulting from the first decision.”\n",
    "\n",
    "(See Bellman, 1957, Chap. III.3.)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Value function \n",
    "\n",
    "* For a given admissible control $v\\in\\mathcal G[t,T]$, define the expected objective functional $J^{(v)}$ as\n",
    "    \n",
    "    $$\n",
    "      J^{(v)}(t,x) = \\E\\left[\\left. g(X^{(v)}_T) + \\int_0^T h(s,X^{(v)}_s,v_s) ds \\right| X_t = x \\right].\n",
    "    $$\n",
    "\n",
    "\n",
    "* The value function $J(t,x)$ for a stochastic control problem is defined as\n",
    "\n",
    "    $$\n",
    "      J(t,x) = \\max_{v\\in\\mathcal G[t,T]} J^{(v)}(t,x).\n",
    "    $$\n",
    "\n",
    "\n",
    "* The value function $J$ at $(t,x)$ is the optimal value of the control problem conditioned on the process starting at $(t,x)$ and applying the optimal control thereafter."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Bellman's principle again\n",
    "\n",
    "The Bellman's principle can be rephrased in terms of value function as follow. For any $0 < \\epsilon < T -t$,\n",
    "\n",
    "$$\n",
    "J(t,x) = \\max_{v\\in\\cG[t,t+\\epsilon]} \\E\\left[\\left. \\int_t^{t+\\epsilon} h(s,X^{(v)}_s,v_s) ds + J(t+\\epsilon,X^{(v)}_{t+\\epsilon}) \\right| \\cF_t \\right].\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Hamilton-Jacobi-Bellman (HJB) equation\n",
    "\n",
    "The value function $J$ satisfies the terminal value problem\n",
    "\n",
    "$$\n",
    "\\p_t J(t,x) + \\max_{v\\in\\cG[t]} \\{\\mathcal L^{(v)} J(t,x) + h(t,x,v) \\} = 0, \\mbox{ for } t < T\n",
    "$$\n",
    "\n",
    "with terminal condition\n",
    "\n",
    "$$\n",
    "  J(T,x) = g(x),\n",
    "$$\n",
    "\n",
    "where $\\mathcal L^{(v)} := \\frac{\\sigma^2}2 \\p_x^2 + \\mu \\p_x$ is the associated infinitesimal generator of the controlled process \n",
    "\n",
    "$$\n",
    "dX^{(v)}_t = \\mu( t,X^{(v)}_t, v_t) dt + \\sigma(t,X^{(v)}_t, v_t) dW_t.\n",
    "$$\n",
    "\n",
    "#### Note\n",
    "\n",
    "* The HJB equation is bascially an infinitesimal version of the Bellman's principle. \n",
    "\n",
    "* The optimal policy (control) is given implicitly in terms of the value function $J$.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Deterministic and stochastic optimal control\n",
    "\n",
    "-   <span>In <span>*deterministic*</span> optimal control, the evolution\n",
    "    of the state vector is deterministic.</span>\n",
    "\n",
    "-   <span>In <span>*stochastic*</span> optimal control, the evolution of\n",
    "    the state vector is stochastic.</span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Almgren and Chriss\n",
    "\n",
    "-   The seminal paper of [Almgren and Chriss]<sup id=\"cite_ref-AlmgrenChriss\" class=\"reference\"><a href=\"#cite_note-AlmgrenChriss\"><span>[</span>2<span>]</span></a></sup> treats the execution of a meta\n",
    "    order as a tradeoff between risk and execution cost.\n",
    "\n",
    "-   According to their formulation:\n",
    "\n",
    "    -   The faster an order is executed, the higher the execution cost\n",
    "\n",
    "    -   The faster an order is executed, the lower the risk (which is\n",
    "        increasing in position size).\n",
    "\n",
    "-   Note that this is inconsistent with the empirical success of the\n",
    "    square-root formula in describing the cost of meta orders.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Almgren and Chriss\n",
    "\n",
    "For simplicity, we consider liquidation of an existing position $X$.\n",
    "Denote the position at time $t$ by $x_t$ with $x_0=X$ and $x_T=0$.\n",
    "\n",
    "[Almgren and Chriss]<sup id=\"cite_ref-AlmgrenChriss\" class=\"reference\"><a href=\"#cite_note-AlmgrenChriss\"><span>[</span>2<span>]</span></a></sup> model market impact and slippage as follows. The stock\n",
    "price $S_t$ evolves as \n",
    "\n",
    "$$dS_t=\\gamma\\,dx_t+\\sigma\\,dZ_t$$\n",
    "\n",
    "and the price\n",
    "$\\tilde S_t$ at which transactions occur is given by\n",
    "\n",
    "$$\\tilde S_t = S_t - \\eta\\,v_t$$\n",
    "\n",
    "where $v_t:=-{\\dot x}_t$ is the rate of\n",
    "trading.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Price path in the Almgren and Chriss model\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/AlmgrenChriss.png\" align = \"center\" width=500></h2>\n",
    "Figure 1: The Almgren and Chriss price path is plotted in orange."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Consistency with empirical observation\n",
    "\n",
    "-   This price path is inconsistent with empirical observation:\n",
    "\n",
    "    -   The average price path during execution is linear.\n",
    "\n",
    "    -   There is no price reversion after completion of the order.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### P&L and cost of trading of a trading strategy\n",
    "\n",
    "Let $x_t$ be a trading strategy. The corresponding P&L (up to time $t$), denoted by $\\Pi_t(x)$, is identified as \n",
    "\n",
    "$$\n",
    "\\Pi_t(x) := x_t (S_t - S_0) + \\int_0^t (S_0 - \\tilde S_\\tau) d x_\\tau.\n",
    "$$\n",
    "\n",
    "- The first term represents the potential cost of shares that are yet to be transacted.\n",
    "\n",
    "- The second term corresponds to the monetary value from the shares that have been transacted up to time $t$.\n",
    "\n",
    "- Obviously, should there be no trade in the time interval $[0,t]$, i.e., $x_s = X$ for all $s \\in [0,t]$, the P&L reads $\\Pi_t(x) = X (S_t - S_0)$; reflecting the P&L from the price movement of the stock.\n",
    "\n",
    "#### <font color=blue>Implementation shortfall as cost of trading </font>\n",
    "\n",
    "Negative P&L is also referred to as the *implementation shortfall*, which will be used as the cost of trading, denoted by $C$ hereafter.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### P&L in Almgren-Chriss model\n",
    "\n",
    "Note that, at the end of execution period $T$, the P&L reads\n",
    "$$\n",
    "  \\Pi_T(x) = x_T (S_T - S_0) + \\int_0^T (S_0 - \\tilde S_u) d x_u,\n",
    "$$\n",
    "should there be $x_T$ shares yet to be transacted. Hence, in Almgren-Chriss model \n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\Pi_T(x) &=& x_T (S_T - S_0) + \\int_0^T (S_0 - \\tilde S_u) d x_u \\\\\n",
    "&=& \\int_0^T [- \\gamma (x_u - X) - \\sigma W_u + \\eta v_u] d x_u \\quad (\\mbox{note that } x_T = 0) \\\\\n",
    "&=& -\\frac\\gamma2 X^2 + \\sigma \\int_0^T x_u d W_u - \\eta \\int_0^T v_u^2 du \\quad (\\mbox{Integration by parts}).\n",
    "\\end{eqnarray*}\n",
    "Therefore, the expected cost corresponding to the trading strategy $x$ is given by  \n",
    "\\begin{eqnarray*}\n",
    "&& \\E\\left[C_T(x)\\right] = \\frac\\gamma2 X^2 + \\eta \\int_0^T \\Eof{v_u^2} du.\n",
    "\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### An observation from Predoiu, Shaikhet and Shreve\n",
    "\n",
    "Suppose the cost associated with a strategy depends on the stock price\n",
    "only through the term \n",
    "\n",
    "$$\\int_0^T\\,S_t\\,dx_t.$$\n",
    "\n",
    "with $S_t$ a martingale.\n",
    "Integration by parts gives\n",
    "\n",
    "$$\\mathbb{E} \\left[\\int_0^T\\,S_t\\,dx_t\\right]=\\mathbb{E} \\left[S_T\\,x_T-S_0\\,x_0-\\int_0^T\\,x_t\\,dS_t\\right]=-S_0\\,X$$\n",
    "\n",
    "which is independent of the trading strategy and we may proceed as if\n",
    "$S_t=0$.\n",
    "\n",
    "<font color=\"red\">\n",
    "####<span>Quote from [Predoiu, Shaikhet, and Shreve]<sup id=\"cite_ref-PredoiuShaikhetShreve\" class=\"reference\"><a href=\"#cite_note-PredoiuShaikhetShreve\"><span>[</span>9<span>]</span></a></sup></span>\n",
    "<span>“...there is no\n",
    "longer a source of randomness in the problem. Consequently, without loss\n",
    "of generality we may restrict the search for an optimal strategy to\n",
    "nonrandom functions of time”.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Corollary\n",
    "\n",
    "-   <span>This observation enables us to easily determine whether or not\n",
    "    a statically optimal strategy will be dynamically optimal.</span>\n",
    "\n",
    "    -   <span>In particular, if the price process is of the form\n",
    "        $$S_t=S_0+\\text{ impact of prior trading} +\\text {noise},$$ and\n",
    "        if there is no risk term, a statically optimal strategy will be\n",
    "        dynamically optimal.</span>\n",
    "\n",
    "    -   <span>If there is a risk term independent of the current stock\n",
    "        price, a statically optimal strategy will again be dynamically\n",
    "        optimal.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Expected cost of VWAP in the Almgren and Chriss model\n",
    "\n",
    "For a VWAP, $v_t=X/T$ where $X$ is the total trade size and $T$ is the\n",
    "duration of the order.\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\E[C_T(x)] &=& \\E\\left[\\frac\\gamma2 X^2 - \\sigma \\int_0^T x_u d W_u + \\eta \\int_0^T \\left(\\frac XT\\right)^2 du \\right] \\\\\n",
    "&=& \\frac\\gamma2 X^2 + \\eta \\frac{X^2}T \\\\\n",
    "&=& \\left(\\frac\\gamma2 + \\frac\\eta{T}\\right)X^2.\n",
    "\\end{eqnarray*}\n",
    "\n",
    "The cost per share of executing an order using VWAP is therefore\n",
    "\n",
    "$$\\hat{C}=\\left(\\frac\\gamma2 + \\frac\\eta{T}\\right)X$$\n",
    "\n",
    "which is linear in the trade\n",
    "size $X$ and inversely proportional to the duration of the order.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The optimal strategy of a risk neutral trader\n",
    "\n",
    "For a risk neutral trader whose objective is to minimize his total cost, the optimal control problem reads \n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&& \\min_{v} \\E\\left[C_T(x)\\right] \\\\\n",
    "&=& \\min_{v} \\left\\{\\frac\\gamma2 X^2 + \\eta \\int_0^T \\Eof{v_u^2} du \\right\\} \\\\\n",
    "&=& \\frac\\gamma2 X^2 + \\eta \\min_v \\int_0^T \\Eof{v_u^2} du,\n",
    "\\end{eqnarray*}\n",
    "\n",
    "where the state variable $x_t$ is driven by $dx_t = -v_t dt$ with the constraints $x_0 = X$ and $x_T = 0$.   \n",
    "Note that, since $S_t$ is not involved in the last expression, we end up with a deterministic control problem which can be solved by the solution to its assocated HJB equation or, due to the simplicity of the dynamics of $x_t$, further reduced to a variational problem. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Variational problem \n",
    "\n",
    "$$\\min_v \\int_0^T\\,v_t^2\\,dt$$\n",
    "\n",
    "with $v_t=-\\dot x_t$ and $x_0 = X$, $x_T = 0$. \n",
    "\n",
    "The Euler-Lagrange equation is then\n",
    "\n",
    "$$\\partial_t v_t=-\\partial_{t,t} x_t=0$$\n",
    "\n",
    "with boundary conditions\n",
    "$x_0=X$ and $x_T=0$ and the solution is obviously\n",
    "\n",
    "$$v_t=\\frac{X}{T};\\, x_t=X\\,\\left(1-\\frac{t}{T}\\right)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Adding a risk term\n",
    "\n",
    "[Almgren and Chriss]<sup id=\"cite_ref-AlmgrenChriss\" class=\"reference\"><a href=\"#cite_note-AlmgrenChriss\"><span>[</span>2<span>]</span></a></sup> add a risk term that penalizes the approximate variance\n",
    "of the trading cost. They claim \n",
    "\n",
    "$$Var \\left[\\int_0^T\\,x_t\\,dS_t\\right] \\approx \\sigma^2\\,\\int_0^T\\,x_t^2\\,dt$$\n",
    "\n",
    "In fact, by It&ocirc;'s isomety, it is an equality if $x_t$ is deterministic. \n",
    "\n",
    "The expected risk-adjusted cost is then given by (temporarily ignore the path independent term $\\frac\\gamma2 X^2$)\n",
    "\n",
    "$$\\eta\\,\\int_0^T\\,{\\dot x}_t^2\\,dt + \\lambda\\,\\sigma^2\\,\\int_0^T\\,x_t^2\\,dt$$\n",
    "\n",
    "for some price of risk $\\lambda$.\n",
    "\n",
    "-   <span>Note the analogies to physics and portfolio theory.</span>\n",
    "\n",
    "    -   <span>The first term looks like kinetic energy and the second\n",
    "        term like potential energy.</span>\n",
    "\n",
    "    -   <span>The expression looks like the objective in mean-variance\n",
    "        portfolio optimization.</span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "The Euler-Lagrange equation becomes $$\\ddot x- \\kappa^2\\,x=0$$ with\n",
    "$$\\kappa^2=\\frac{\\lambda\\,\\sigma^2}{\\eta}$$ The solution is a linear\n",
    "combination of terms of the form $e^{\\pm \\kappa t}$ that satisfies the\n",
    "boundary conditions $x_0=X$, $x_T=0$. The solution is then\n",
    "\n",
    "<font color=\"red\">\n",
    "<span>Almgren-Chriss optimal strategy</span>\n",
    "\n",
    "<a name=\"eq:optimalAC\"></a>(2)\n",
    "$$x(t)=X\\,\\frac{\\sinh \\kappa (T-t)}{\\sinh \\kappa T}$$\n",
    "\n",
    "\n",
    "\n",
    "<font color=\"black\">\n",
    "Once again, this statically optimal solution is dynamically optimal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Efficient frontier in the Almgren Chriss model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%load_ext rpy2.ipython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAYAAAB91L6VAAAD8GlDQ1BJQ0MgUHJvZmlsZQAAOI2N\nVd1v21QUP4lvXKQWP6Cxjg4Vi69VU1u5GxqtxgZJk6XpQhq5zdgqpMl1bhpT1za2021Vn/YCbwz4\nA4CyBx6QeEIaDMT2su0BtElTQRXVJKQ9dNpAaJP2gqpwrq9Tu13GuJGvfznndz7v0TVAx1ea45hJ\nGWD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JWJUbN3bsWI0bN04TJkxQ27ZtdcUVV6ikpMRbxK67dOlSTZs2rcZ1\nK5fDewQQSF+AAE7fjjURyGkBG6p77723F7LVG2rD9vLLL9eyZcv0xBNP6MUXX9QjjzziLdaxY0fZ\ns6FLS0t17733Vl+Vzwgg4JMAAewTJMUgkIsCNkBffvllbyRcuX1PPvmkd3zXcRyNGTOmyqVHjRs3\nVoMGDXTXXXfpmmuu0fLlyyuvynsEEPBJgAD2CZJiEMhFAXtN78UXX+wdFy7bxWzbeeaZZ3rHhe0I\nuXPnzorFYt4u6crbcPDBB3snb9mRMhMCCPgv4Lhm8r9YSkQAgXwQsGdEb926Vc2aNcuH5tJGBCIl\nQABHqjvZGAQQQACBfBFgF3S+9BTtRAABBBCIlAABHKnuZGMQQAABBPJFgADOl56inQgggAACkRIg\ngCPVnWwMAggggEC+CBDA+dJTtBMBBBBAIFICBHCkupONQQABBBDIFwECOF96inYigAACCERKgACO\nVHeyMQgggAAC+SJAAOdLT9FOBBBAAIFICRDAkepONgYBBBBAIF8ECOB86SnaiQACCCAQKQECOFLd\nycYggAACCOSLAAGcLz1FOxFAAAEEIiVAAEeqO9kYBBBAAIF8ESCA86WnaCcCCCCAQKQECOBIdScb\ngwACCCCQLwL/H4WXLeYkh/RkAAAAAElFTkSuQmCC\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "\n",
    "#-------------------------------------------------\n",
    "# Figure 2: Almgren-Chriss Efficient frontier plot\n",
    "costOpt <- function(kappa,T){1/4*kappa*(1/sinh(kappa*T))^2*(2*kappa*T + sinh(2*kappa*T))}\n",
    "riskOpt <- function(kappa,T){1/4*kappa*(1/sinh(kappa*T))^2*(-2*kappa*T + sinh(2*kappa*T))}\n",
    "\n",
    "costVWAP <- function(kappa,T){1/T}\n",
    "riskVWAP <- function(kappa,T){kappa^2*T/3}\n",
    "\n",
    "tt <- (20:1000)/200\n",
    "rOpt <- riskOpt(1,tt);\n",
    "cOpt <- costOpt(1,tt);\n",
    "rVWAP <- riskVWAP(1,tt);\n",
    "cVWAP <- costVWAP(1,tt);\n",
    "plot(rOpt,cOpt,type=\"l\",col=\"red\",xlab=\"Risk\",ylab=\"Cost\",xaxt=\"n\",yaxt=\"n\");\n",
    "points(rVWAP,cVWAP,type=\"l\",col=\"blue\",lty=2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 2: The optimal strategy [(2)](#eq:optimalAC) is in red and VWAP in blue."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Deterministic control problem\n",
    "\n",
    "The problem of minimizaing expected risk-adjusted cost can be recast as the following deterministic (since $S_t$ is not involved) control problem \n",
    "\n",
    "$$\\min_v \\left\\{\\eta\\,\\int_0^T\\,{\\dot x}_t^2\\,dt + \\lambda\\,\\sigma^2\\,\\int_0^T\\,x_t^2\\,dt \\right\\}$$\n",
    "\n",
    "with state vairable $x_t$ driven by $dx_t = -v_t dt$ and $x_0 = X$. Similar to the stochastic case, the value function $J$ is defined by\n",
    "\n",
    "$$\n",
    "J(t,x) = \\min_{v\\in\\mathcal G[t,T]} \\left\\{\\eta\\,\\int_t^T\\,{\\dot x}_t^2\\,dt + \\lambda\\,\\sigma^2\\,\\int_t^T\\,x_t^2\\,dt \\right\\}\n",
    "$$\n",
    "\n",
    "with $x_t = x$.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The HJB equation\n",
    "\n",
    "The HJB equation reads\n",
    "\n",
    "<a name=\"eq:HJB1\"></a>(3)\n",
    "$$\\frac{\\partial J}{\\partial t} + \\lambda\\,\\sigma^2\\,x^2 + \\min_{v \\in \\mathcal{G}}\\left\\{-v J_x + \\eta\\,v^2\\right\\}=0.$$\n",
    "\n",
    "The optimal choice of $v$ is $$v^* = \\frac{J_x}{2\\eta}.$$\n",
    "Substituting back into [(3)](#eq:HJB1) gives\n",
    "\n",
    "<a name=\"eq:HJB2\"></a>(4)\n",
    "$$\\frac{\\partial J}{\\partial t} + \\lambda \\sigma^2 x^2 - \\frac{J_x^2}{4\\eta} = 0$$\n",
    "\n",
    "which we solve by imposing the ansatz $J(t,x) = a(t) x^2$.\n",
    "\n",
    "#### Remark\n",
    "To take into account the terminal condition that $x_T = 0$, we set the terminal condition for the HJB equation as \n",
    "\n",
    "$$\\lim_{t\\uparrow T}J(t,x)=\\begin{cases}0&\\text{if $x=0$,}\\\\\n",
    "+\\infty&\\text{if $x\\neq0$.}\n",
    "\\end{cases}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Solution to HJB equation \n",
    "\n",
    "By substituting the ansatz $J(t,x) = a(t)x^2$ into the HJB equation [(4)](#eq:HJB2), we obtain \n",
    "\n",
    "$$\n",
    "a' x^2 + \\lambda \\sigma^2 x^2 - \\frac{(2ax)^2}{4\\eta} = 0. \n",
    "$$\n",
    "\n",
    "Setting the coefficient of $x^2$ equal to zero yields the ODE for $a$:\n",
    "\n",
    "$$\n",
    "a' + \\lambda \\sigma^2 - \\frac{a^2}\\eta = 0.\n",
    "$$\n",
    "\n",
    "Taking into account the terminal condition, we obtain the unique solution for $a$ as\n",
    "\n",
    "$$\n",
    "a(t) = \\kappa \\eta \\coth(\\kappa(T-t)).\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal strategy\n",
    "\n",
    "The optimal trading rate $v^*$ is obtained via the value function $J$ as\n",
    "\n",
    "$$\n",
    "v_t^* = \\frac{J_x}{2\\eta} = \\frac{a(t)}{\\eta} x^*_t = \\kappa \\coth(\\kappa(T-t)) x_t^*.\n",
    "$$\n",
    "\n",
    "Finally, recall that $v_t = -\\dot x_t$, by solving the ODE \n",
    "\n",
    "$$\n",
    "-\\dot x_t = \\kappa \\coth(\\kappa(T-t)) x_t\n",
    "$$\n",
    "\n",
    "with initial conditional $x_0 = X$, we obtain the Almgren-Chriss solution \n",
    "\n",
    "$$\n",
    "x_t^* = X \\frac{\\sinh \\kappa (T-t)}{\\sinh \\kappa T}.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### What happens if we change the risk term?\n",
    "\n",
    "Suppose we penalize average VaR instead of variance. This choice of risk\n",
    "term has the particular benefit of being linear in the position size.\n",
    "The expected risk-adjusted cost is then given by\n",
    "\n",
    "$$C = \\eta\\,\\int_0^T\\,{\\dot x}_t^2\\,dt + \\lambda\\,\\sigma\\,\\int_0^T\\,x_t\\,dt$$\n",
    "\n",
    "for some price of risk $\\lambda$.\n",
    "\n",
    "The Euler-Lagrange equation becomes \n",
    "\n",
    "$$\\ddot x- A=0$$\n",
    "\n",
    "with\n",
    "\n",
    "$$A=\\frac{\\lambda\\,\\sigma}{2\\,\\eta}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "The solution is a quadratic of the form $A\\,t^2/2+B \\,t + C$ that\n",
    "satisfies the boundary conditions $x_0=X$, $x_T=0$. The solution is then\n",
    "\n",
    "<a name=\"eq:VaRgeneral\"></a>(5)\n",
    "$$x(t)=\\left(X-\\frac{A \\, T}{2}\\,t\\right)\\,\\left(1-\\frac{t}{T}\\right)$$\n",
    "\n",
    "In contrast to the previous case where the cost function is monotonic\n",
    "decreasing in the trading rate and the optimal choice of liquidation\n",
    "time is $\\infty$, in this case, we can compute an optimal liquidation\n",
    "time.\n",
    "\n",
    "When $T$ is optimal, we have\n",
    "$$\\frac{\\partial C}{\\partial T}\\propto {\\dot x}_T^2 + A\\,x_T=0$$ from\n",
    "which we deduce that $\\dot x_T=0$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Substituting into [(5)](#eq:VaRgeneral) and solving for the optimal time\n",
    "$T^\\star$ gives $$T^\\star=\\sqrt{\\frac{2\\,X}{A}}$$\n",
    "\n",
    "With this optimal choice $T=T^\\star$, the optimal strategy becomes\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "x(t)&=&X\\,\\left(1-\\frac{t}{T}\\right)^2\\\\\n",
    "u(t)&=&-\\dot x(t)=2\\,X\\,\\left(1-\\frac{t}{T}\\right)\\end{eqnarray*}\n",
    "\n",
    "Again, the static strategy is dynamically optimal, independent of the\n",
    "stock price."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### ABM vs GBM\n",
    "\n",
    "-   One of the reasons that the statically optimal strategy is\n",
    "    dynamically optimal is that the stock price process is assumed to be\n",
    "    arithmetic Brownian motion (ABM).\n",
    "\n",
    "-   If for example geometric Brownian motion (GBM) is assumed, the\n",
    "    optimal strategy depends on the stock price.\n",
    "    \n",
    "   \n",
    "\n",
    "-   How dependent is the optimal strategy on dynamical assumptions for\n",
    "    the underlying stock price process?\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Forsyth et al.\n",
    "\n",
    "-   <span>[Forsyth et al.]<sup id=\"cite_ref-Forsyth\" class=\"reference\"><a href=\"#cite_note-Forsyth\"><span>[</span>4<span>]</span></a></sup> solve the HJB equation numerically under geometric\n",
    "    Brownian motion with variance as the risk term so that the (random)\n",
    "    cost is given by\n",
    "    \n",
    "    $$\\mathcal{C} =\\eta\\,\\int_0^T\\,{\\dot x}_t^2\\,dt+\\lambda\\,\\sigma^2\\,\\int_0^T\\,S_t^2\\,x_t^2\\,dt$$\n",
    "    \n",
    "    </span>\n",
    "\n",
    "-   <span>The efficient frontier is found to be virtually identical to\n",
    "    the frontier computed in the arithmetic Brownian motion case.</span>\n",
    "\n",
    "-   <span>The problem of finding the optimal strategy is ill-posed; many\n",
    "    strategies lead to almost the same value of the cost\n",
    "    function.</span>\n",
    "\n",
    "-   <span>It is optimal to trade faster when the stock price is high so\n",
    "    as to reduce variance. The optimal strategy is\n",
    "    aggressive-in-the-money when selling stock and passive-in-the-money\n",
    "    when buying stock.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Gatheral and Schied\n",
    "\n",
    "[Gatheral and Schied]<sup id=\"cite_ref-GatheralSchied\" class=\"reference\"><a href=\"#cite_note-GatheralSchied\"><span>[</span>6<span>]</span></a></sup> take time-averaged VaR as the risk term so that\n",
    "\n",
    "<a name=\"ControllProblemEq\"></a>(6)\n",
    "$$C(0,X,S_0)=\\inf_{v\\in\\mathcal{G} }\\mathbb{E} \\Big[\\,\\int_0^T v_t^2\\,dt+\\lambda \\int_0^T\\,S_t\\,x_t\\,dt\\,\\Big],$$\n",
    "\n",
    "where the state variables are driven by \n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&& dS_t = \\sigma S_t dW_t, \\\\\n",
    "&& dx_t = -v_t dt,\n",
    "\\end{eqnarray*}\n",
    "\n",
    "and $\\mathcal{G} $ is the set of admissible strategies.\n",
    "\n",
    "The value function $C(t,x,s)$ should then satisfy the following Hamilton-Jacobi-Bellman\n",
    "PDE:\n",
    "\n",
    "<a name=\"eq:HJB\"></a>(7)\n",
    "$$C_t + \\frac12\\,\\sigma^2\\,s^2\\, C_{ss} + \\lambda\\, sx + \\inf_{v\\in\\mathbb{R} }(v^2-v\\,C_x) = 0.$$\n",
    "\n",
    "with terminal condition\n",
    "\n",
    "<a name=\"InitialCond\"></a>(8)\n",
    "$$\\lim_{t\\uparrow T}C(t,x,s)=\\begin{cases}0&\\text{if $x=0$,}\\\\\n",
    "+\\infty&\\text{if $x\\neq0$.}\n",
    "\\end{cases}$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The first order criterion \n",
    "\n",
    "By substitute the first order criterion $v = \\frac{C_x}2$ into the HJB equation we have \n",
    "\n",
    "$$C_t + \\frac12\\,\\sigma^2\\,s^2\\, C_{ss} + \\lambda\\, sx - \\frac{C_x^2}4 = 0.$$\n",
    "\n",
    "Using the ansatz $C(t,s,x) = a(t)s^2 + b(t) sx + c(t)x^2$ we have \n",
    "\n",
    "$$\n",
    "a' s^2 + b' s x + c'x^2 + \\sigma^2 s^2 a + \\lambda sx - \\frac{(b s + 2cx)^2}4  = 0\n",
    "$$\n",
    "\n",
    "Compare the coefficients and obtain the following system of ODEs\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "s^2 &:& a' + \\sigma^2 a - \\frac{b^2}4 = 0, \\\\\n",
    "sx &:& b' + \\lambda - bc = 0, \\\\\n",
    "x^2 &:& c' - c^2 = 0.\n",
    "\\end{eqnarray*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Solution to the HJB equation \n",
    "\n",
    "Taking into account the boundary condition [(8)](#InitialCond), we obtain the solution to the system of ODEs as \n",
    "\n",
    "\\begin{eqnarray*}\n",
    "&& a(t) = \\frac{\\lambda^2}{8\\sigma^6} \\left[1 - e^{\\sigma^2(T-t)} + \\sigma^2(T-t) + \\frac12\\sigma^4(T-t)^2\\right], \\\\\n",
    "&& b(t) = \\frac\\lambda2(T-t), \\\\\n",
    "&& c(t) = \\frac1{T-t}.\n",
    "\\end{eqnarray*}\n",
    "\n",
    "Hence, the optimal trading rate $v^*$ is given by the value funciton as \n",
    "\n",
    "$$\n",
    "v_t^* = \\frac{C_x}2 = \\frac\\lambda4(T-t) s_t + \\frac{x_t^*}{T-t}.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The optimal strategy under GBM\n",
    "\n",
    "<font color=\"red\">\n",
    "####<span>Theorem</span>\n",
    "The unique optimal trade execution strategy attaining the\n",
    "infimum in [(6)](#ControllProblemEq) is\n",
    "\n",
    "<a name=\"eq:GBMoptimalStrategy\"></a>(9)\n",
    "$$x^*_t=\\Big(\\frac{T-t}{T}\\Big)\\bigg[X-\\frac{\\lambda T}{4}\\int_0^t {S_u}\\,du\\bigg]$$\n",
    "\n",
    "Moreover, the value of the minimization problem in [(6)](#ControllProblemEq) is given by\n",
    "\n",
    "<a name=\"eq:CeGeneralForm\"></a>(10)\n",
    "\\begin{eqnarray*}\n",
    "C&=&\\mathbb{E} \\Big[\\,\\int_0^T\\bigg\\{(\\dot x^*_t)^2+\\lambda x^*_tS_t\\bigg\\}\\,dt\\,\\Big]\\nonumber\\\\\n",
    "&=&\\frac{X^2}T+\\frac12\\lambda \\,T\\,X\\,S_0 + \\frac{\\lambda^2}{8\\,\\sigma^6}\\,S_0^2\\,\\Big(1 - e^{\\sigma^2\\, T} + \\sigma^2 \\,T + \\frac12\\,\\sigma^4\\,T^2\\Big).\\end{eqnarray*}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The optimal strategy under ABM\n",
    "\n",
    "If we assume ABM, $S_t=S_0\\,(1+\\sigma W_t)$, instead of GBM, the risk\n",
    "term becomes\n",
    "\n",
    "<a name=\"ABMriskterm\"></a>(11)\n",
    "$$\\widehat{\\lambda} \\,S_0\\int_0^Tx_t\\,dt.$$\n",
    "\n",
    "As we already showed, the optimal strategy under ABM is just the static\n",
    "version of the dynamic strategy [(9)](#eq:GBMoptimalStrategy) obtained by replacing $S_t$ with its\n",
    "expectation $\\mathbb{E} [S_t]=S_0$, a strategy qualitatively similar to\n",
    "the Almgren-Chriss optimal strategy.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Comparing optimal strategies under ABM and GBM\n",
    "\n",
    "As before, define the characteristic timescale\n",
    "$$T^\\star=\\sqrt{\\frac{4\\,X}{{\\lambda}\\,S_0}}$$ and choose the\n",
    "liquidation time $T$ to be $T^\\star$.\n",
    "\n",
    "With $T=T^\\star$, the optimal trading rate under ABM becomes\n",
    "\n",
    "<a name=\"eq:vA\"></a>(12)\n",
    "$$v^A(t)= \\frac{x_t}{T-t}\\,+\\frac{X}{T^2}\\,(T-t)=\\frac{2\\,X}{T}\\,\\bigg(1-\\frac{t}{T}\\bigg)$$\n",
    "\n",
    "and the optimal trading rate under GBM becomes\n",
    "\n",
    "<a name=\"eq:vG\"></a>(13)\n",
    "$$v^G(t)= \\frac{x_t}{T-t}\\,+\\frac{X}{T^2}\\,\\frac{S_t}{S_0}\\,(T-t).$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Comparing optimal strategies under ABM and GBM\n",
    "\n",
    "In the following slide:\n",
    "\n",
    "-   The upper plots show rising and falling stock price scenarios\n",
    "    respectively; the trading period is 20 days and daily volatility is\n",
    "    $4\\%$.\n",
    "\n",
    "-   The lower plots show the corresponding optimal trading rates from [(12)](#eq:vA)\n",
    "    and [(13)](#eq:vG); the optimal trading rate under ABM is in orange and the\n",
    "    optimal trading rate under GBM is in blue.\n",
    "\n",
    "-   Even with such extreme parameters and correspondingly extreme\n",
    "    changes in stock price, the differences in optimal trading rates are\n",
    "    minimal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### <h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/optimalGBMplots.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Remarks\n",
    "\n",
    "-   For reasonable values of $\\sigma^2\\,T \\ll 1$, there is almost no\n",
    "    difference in expected costs and risks between the optimal\n",
    "    strategies under ABM and GBM assumptions.\n",
    "\n",
    "-   Intuitively, although the optimal strategy is stock price-dependent\n",
    "    under GBM assumptions but not under ABM assumptions, when\n",
    "    $\\sigma^2\\,T \\ll 1$, the difference in optimal frontiers is tiny\n",
    "    because the stock-price $S_t$ cannot diffuse very far away from\n",
    "    $S_0$ in the short time available.\n",
    "\n",
    "-   Equivalently, as in the plots, there can only be a small difference\n",
    "    in optimal trading rates under the two assumptions.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Almgren 2005 model\n",
    "\n",
    "In the (2005) model of [Almgren]<sup id=\"cite_ref-Almgren\" class=\"reference\"><a href=\"#cite_note-Almgren\"><span>[</span>1<span>]</span></a></sup>, the stock price $S_t$ evolves as\n",
    "\n",
    "$$dS_t=\\gamma\\,d x_t+\\sigma\\,dZ_t$$\n",
    "\n",
    "and the price $\\tilde S_t$ at which\n",
    "we transact is given by \n",
    "\n",
    "$$\\tilde S_t = S_t - \\eta\\,v_t^\\delta$$\n",
    "\n",
    "where\n",
    "$v_t:=-{\\dot x}_t$ is the rate of trading."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "The expected cost of trading is then given by\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\mathcal{C} &=&\\mathbb{E} \\left[\\int_0^T\\,\\tilde S_t\\,v_t\\,dt\\right]\\\\\n",
    "&=&\\int_0^T\\,(\\gamma\\,x_t+\\eta\\,v_t^\\delta)\\,v_t\\,dt\\\\\n",
    "&=&\\frac \\gamma 2\\,(x_T^2-x_0^2)+\\eta\\,\\int_0^T\\,v_t^{1+\\delta}\\,dt\\end{eqnarray*}\n",
    "\n",
    "where wlog, we have set $S_0=0$.\n",
    "\n",
    "We see that the first term corresponding to permanent impact is\n",
    "independent of the trading strategy, as it should be. The second term is\n",
    "convex in the trading rate so the minimum cost strategy is again VWAP."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Applications of the Almgren-Chriss framework\n",
    "\n",
    "-   Although the Almgren and Chriss price process is not particularly\n",
    "    realistic, it leads to a tractable framework for solving a number of\n",
    "    interesting practical problems.\n",
    "\n",
    "-   Applications include:\n",
    "\n",
    "    -   Portfolio liquidation\n",
    "\n",
    "    -   Optimal liquidation with a dark pool (<span>*e.g.*</span>\n",
    "        [Kratz and Schöneborn]<sup id=\"cite_ref-KratzSchoeneborn\" class=\"reference\"><a href=\"#cite_note-KratzSchoeneborn\"><span>[</span>7<span>]</span></a></sup>)\n",
    "\n",
    "    -   Optimal delta-hedging of options under transactions costs\n",
    "        (<span>*e.g.*</span> [Li and Almgren]<sup id=\"cite_ref-LiAlmgren\" class=\"reference\"><a href=\"#cite_note-LiAlmgren\"><span>[</span>8<span>]</span></a></sup>)\n",
    "\n",
    "    -   Optimal liquidation in the presence of a trading signal\n",
    "        (<span>*e.g.*</span> [Almgren(2012)]<sup id=\"cite_ref-AlmgrenSignal\" class=\"reference\"><a href=\"#cite_note-AlmgrenSignal\"><span>[</span>3<span>]</span></a></sup>)\n",
    "        \n",
    "\n",
    "-   As an example, following [Kratz and Schöneborn]<sup id=\"cite_ref-KratzSchoeneborn\" class=\"reference\"><a href=\"#cite_note-KratzSchoeneborn\"><span>[</span>7<span>]</span></a></sup>, we will now solve the\n",
    "    optimal liquidation problem in the presence of a dark pool under\n",
    "    Almgren-Chriss assumptions.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal liquidation with a dark pool\n",
    "\n",
    "-   We suppose we have one primary lit venue and one dark pool.\n",
    "\n",
    "-   Trading in the lit venue incurs temporary market impact according to\n",
    "    the usual Almgren-Chriss assumptions.\n",
    "\n",
    "-   Trading in the dark pool is costless.\n",
    "\n",
    "-   Dark pool executions do not affect the price in the primary venue.\n",
    "\n",
    "-   Trade executions arrive in the dark pool as a Poisson process with\n",
    "    intensity $\\theta$.\n",
    "\n",
    "-   When a trade occurs in the dark pool, your entire posted quantity\n",
    "    $y_t$ is executed.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### State variables and equations\n",
    "\n",
    "Denote the current position by $x_t$, the trading rate by\n",
    "$v_t=-\\dot x_t$, and the quantity currently posted in the dark pool by\n",
    "$y_t$.\n",
    "\n",
    "The state variable is thus $x_t$ and the controls are $v_t$ and $y_t$.\n",
    "The state equation is \n",
    "\n",
    "$$dx_t =-v_t\\,dt-y_t\\,d\\pi_t$$\n",
    "\n",
    "where\n",
    "$$d\\pi_t=\\left\\{\\begin{array}{ll}\n",
    "1&\\text{ with probability } \\theta\\,dt\\\\\n",
    "0&\\text{ with probability } 1-\\theta\\,dt.\n",
    "\\end{array}\n",
    "\\right.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Cost of liquidation\n",
    "\n",
    "As before, the expected cost of liquidation (with risk penalty) is given\n",
    "(as of time $t$) by\n",
    "\n",
    "$$\\mathcal{C} (t)=\\eta\\,\\mathbb{E} \\left[\\int_t^T\\, (\\dot x_u^2+\\kappa^2\\,x_u^2)\\,du\\right]$$\n",
    "\n",
    "with $$\\kappa^2=\\frac{\\lambda\\,\\sigma^2}{\\eta}.$$\n",
    "\n",
    "The contribution to the change in cost from the continuous variables is\n",
    "\n",
    "$$d\\mathcal{C} =\\eta \\,(v_t^2+\\kappa^2\\,x_t^2)\\,dt-v_t\\,\\mathcal{C} _x\\,dt$$\n",
    "\n",
    "and the contribution from a dark pool execution (if it occurs) is\n",
    "\n",
    "$$d\\mathcal{C} =\\mathcal{C} (x_t-y_t)-\\mathcal{C} (x).$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The HJB equation\n",
    "\n",
    "Imposing Bellman’s principle of optimality:\n",
    "$$\\mathcal{C} _t=\\mathbb{E} \\left[\\int_t^{t+\\Delta}\\,h(t,x_u,y_u,{v}_u)\\,du+\\mathcal{C} _{t+\\Delta}\\right]$$\n",
    "and using $\\mathbb{E} [d\\pi_t]=\\theta\\,dt$, we get\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\mathcal{C} _t &\\approx & \\mathcal{C} _t+\\left\\{h(t,x_u,{y}_t,{v}_t)+\\frac{\\partial \\mathcal{C} }{\\partial t}+\\mathcal{L}^v_t \\,\\mathcal{C} + \\theta\\,\\left[\\mathcal{C} (x_t-y_t)-\\mathcal{C} (x_t)\\right]\\right\\}\\,\\Delta.\\end{eqnarray*}\n",
    "\n",
    "Taking the limit $\\Delta \\to 0$ gives the HJB equation for this problem:\n",
    "\n",
    "<font color=\"red\">\n",
    "####<span>Kratz-Schöneborn HJB equation</span>\n",
    "\n",
    "<a name=\"eq:HJB_KS\"></a>(14)\n",
    "$$\\frac{\\partial \\mathcal{C} }{\\partial t}+\\eta\\,\\kappa^2\\,x_t^2+\\min_{v,y \\in \\mathcal{G} }\\left\\{ -v \\,\\mathcal{C} _x+\\eta\\,v^2 +\\theta\\,\\left[\\mathcal{C} (x_t-y)-\\mathcal{C} (x_t)\\right]\\right\\} =0$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The first order conditions\n",
    "\n",
    "The value of $y$ that minimizes\n",
    "$\\left[\\mathcal{C} (x_t-y)-\\mathcal{C} (x_t)\\right]$ is obviously\n",
    "$y^\\star=x_t$.\n",
    "\n",
    "-   This is completely intuitive; if there is no cost of execution in\n",
    "    the dark pool and such executions don’t affect the price in the\n",
    "    primary venue, continuously post the full amount in the dark pool.\n",
    "\n",
    "Differentiating wrt $v$, we get the first order condition on $v$\n",
    "\n",
    "$$v^\\star=\\frac{1}{2\\,\\eta}\\,\\mathcal{C} _x.$$\n",
    "\n",
    "Substituting back into [(14)](#eq:HJB_KS),\n",
    "we get\n",
    "\n",
    "$$\\frac{\\partial \\mathcal{C} }{\\partial t}+\\eta\\,\\kappa^2\\,x_t^2 -\\frac{1}{4\\,\\eta}\\,(\\mathcal{C} _x)^2 -\\theta\\,\\mathcal{C} =0$$\n",
    "\n",
    "As before, we solve the HJB equation by imposing the ansatz \n",
    "\n",
    "$$\n",
    "\\mathcal C(t,x) = a(t) x^2.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Solution to the HJB equation \n",
    "\n",
    "Substituting the ansatz into the HJB equation yields the ODE for $a$\n",
    "\n",
    "$$\n",
    "a' + \\eta \\kappa^2 - \\frac{(2a)^2}{4\\eta} - \\theta a = 0.\n",
    "$$\n",
    "\n",
    "Taking into account the terminal condition as in [(8)](#InitialCond), the solution of $a$ is given by \n",
    "\n",
    "$$\n",
    "a(t) = \\eta \\left\\{\\frac{\\tilde \\theta}{2}\\,\\coth \\left(\\frac{\\tilde \\theta}{2}\\,(T-t)\\right)-\\frac \\theta 2\\right\\},\n",
    "$$\n",
    "\n",
    "where $\\tilde \\theta^2=\\theta^2+4\\,\\kappa^2$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal strategy \n",
    "\n",
    "The optimal trading rate $v_t^\\star$ is determined via the value function $\\mathcal C$ as \n",
    "\n",
    "$$v^\\star=\\frac{1}{2\\,\\eta}\\,\\mathcal{C} _x = \\frac{a(t)}\\eta x_t = \\left\\{\\frac{\\tilde \\theta}{2}\\,\\coth \\left(\\frac{\\tilde \\theta}{2}\\,(T-t)\\right)-\\frac \\theta 2\\right\\} x_t^\\star$$.\n",
    "\n",
    "Hence, by solving \n",
    "\n",
    "$$-\\dot x_t = \\left\\{\\frac{\\tilde \\theta}{2}\\,\\coth \\left(\\frac{\\tilde \\theta}{2}\\,(T-t)\\right)-\\frac \\theta 2\\right\\} x_t^\\star$$\n",
    "\n",
    "with the initial condition $x_0 = X$, the optimal trading strategy $x_t^\\star$ is given by \n",
    "\n",
    "<a name=\"eq:optKS\"></a>(15)\n",
    "$$x^\\star(t)=X \\,e^{\\frac{\\theta\\,t }{2}}\\,\\frac{\\sinh \\left(\\frac{1}{2} (T-t) \\sqrt{\\theta ^2+4 \\kappa ^2}\\right)}{ \\sinh\\left(\\frac{1}{2} T \\sqrt{\\theta ^2+4 \\kappa ^2}\\right) }$$\n",
    "\n",
    "which obviously gives the usual Almgren-Chriss strategy in the\n",
    "limit $\\theta \\to 0$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Remarks on the solution\n",
    "\n",
    "Recall that \n",
    "$$v^\\star(t) = \\left\\{\\frac{\\tilde \\theta}{2}\\,\\coth \\left(\\frac{\\tilde \\theta}{2}\\,(T-t)\\right)-\\frac \\theta 2\\right\\}\\,x^\\star(t).$$\n",
    "where $\\tilde \\theta^2=\\theta^2+4\\,\\kappa^2$.\n",
    "\n",
    "-   The more likely an execution in the dark pool, the slower the\n",
    "    optimal rate of trading in the lit venue.\n",
    "\n",
    "-   “Every closed-form solution to the HJB equation is a victory over nature” – quote attributed to <span>Ø</span>ksendal.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal single stock strategy from [Kratz and Schöneborn]<sup id=\"cite_ref-KratzSchoeneborn\" class=\"reference\"><a href=\"#cite_note-KratzSchoeneborn\"><span>[</span>7<span>]</span></a></sup>\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/KSFig1.png\" align = \"center\" width=600></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal portfolio liquidation strategy\n",
    "\n",
    "-   In the portfolio case, it is no longer optimal in general to place\n",
    "    the entire remaining quantity in the dark pool\n",
    "\n",
    "    -   because obtaining a dark pool execution may unbalance the\n",
    "        portfolio and incur a greater risk cost.\n",
    "\n",
    "-   If the starting portfolio is balanced, the optimal quantity to place\n",
    "    in the dark pool tends to be small\n",
    "\n",
    "    -   The optimal strategy is to trade out of the position almost\n",
    "        linearly.\n",
    "\n",
    "-   If the starting portfolio is unbalanced, the optimal quantity to\n",
    "    place in the dark pool tends to be a large proportion of the\n",
    "    remaining quantity.\n",
    "\n",
    "-   It may be optimal to short a stock that one is trying to liquidate\n",
    "    if it is a good hedge for other less liquid positions (think of\n",
    "    SPY).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal portfolio strategy from [Kratz and Schöneborn]<sup id=\"cite_ref-KratzSchoeneborn\" class=\"reference\"><a href=\"#cite_note-KratzSchoeneborn\"><span>[</span>7<span>]</span></a></sup>\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/04/KSFig2.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Summary\n",
    "\n",
    "-   The Almgren-Chriss price process is in practice the most\n",
    "    widely-used.\n",
    "\n",
    "-   It forms the basis for many of the algorithms and most of the\n",
    "    thinking in algorithmic execution.\n",
    "\n",
    "    -   despite the fact that it is unrealistic: market impact decays\n",
    "        instantaneously and it is completely incompatible with the\n",
    "        square-root law.\n",
    "\n",
    "-   Because of the analytical tractability of the Almgren-Chriss\n",
    "    framework, there are closed-form or quasi-closed-form solutions for\n",
    "    many problems of practical interest.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### References\n",
    "\n",
    "<br />\n",
    "\n",
    "<div class=\"reflist\" style=\"list-style-type: decimal;\">\n",
    "\n",
    "<ol>\n",
    "\n",
    "  <li id=\"cite_note-Almgren\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Almgren\">^</a></b></span>Robert Almgren, Chee Thum, Emmanuel Hauptmann, and Hong Li, Equity\n",
    "market impact, <span>*Risk*</span> 57–62 (July 2005).\n",
    "  </li>\n",
    "\n",
    "  <li id=\"cite_note-AlmgrenChriss\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AlmgrenChriss\">^</a></b></span>Robert Almgren and Neil Chriss, Optimal execution of portfolio\n",
    "transactions, <span>*Journal of Risk*</span> <span>**3**</span> 5–40\n",
    "(2001).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-AlmgrenSignal\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-AlmgrenSignal\">^</a></b></span>Robert Almgren, Optimal Trading with Stochastic Liquidity and\n",
    "Volatility, <span>*SIAM Journal on Financial Mathematics*</span>,\n",
    "(2012).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-Forsyth\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Forsyth\">^</a></b></span>P.A. Forsyth, J.S. Kennedy, S. T. Tse, and H. Windcliff, Optimal trade\n",
    "execution: a mean quadratic variation approach. <span>*Journal of\n",
    "Economic Dynamics and Control*</span> <span>**36**</span>(12), 1971–1991\n",
    "(2012).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-GatheralSchiedReview\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GatheralSchiedReview\">^</a></b></span>Jim Gatheral and Alexander Schied, Dynamical models of market impact and\n",
    "algorithms for order execution, <span>*HANDBOOK ON SYSTEMIC RISK,\n",
    "Jean-Pierre Fouque, Joseph A. Langsam, eds.*</span> 579–599 available at\n",
    "<http://ssrn.com/abstract=2034178> (2013).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-GatheralSchied\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-GatheralSchied\">^</a></b></span>Jim Gatheral and Alexander Schied, Optimal Trade Execution under\n",
    "Geometric Brownian Motion in the Almgren and Chriss Framework,\n",
    "<span>*International Journal of Theoretical and Applied Finance*</span>\n",
    "<span>**14**</span>(3) 353–368 (2011).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-KratzSchoeneborn\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-KratzSchoeneborn\">^</a></b></span>Peter Kratz and Torsten Schöneborn,\n",
    "Portfolio liquidation in dark pools in continuous time, <span>*Mathematical Finance*</span> (2013).\n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-LiAlmgren\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-LiAlmgren\">^</a></b></span>Tianhui Michael Li and Robert Almgren, A fully-dynamic closed-form\n",
    "solution for $\\Delta$-hedging with market impact, <span>*Operations\n",
    "Research*</span> (2013).\n",
    "  </li>\n",
    "    \n",
    "  <li id=\"cite_note-PredoiuShaikhetShreve\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-PredoiuShaikhetShreve\">^</a></b></span>Silviu Predoiu, Gennady Shaikhet and Steven Shreve, Optimal execution in\n",
    "a general one-sided limit-order book, <span>*SIAM Journal on Financial\n",
    "Mathematics*</span> <span>**2**</span> 183–212 (2011).\n",
    "  </li>\n",
    "    \n",
    "  <li id=\"cite_note-Weiss\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Weiss\">^</a></b></span>Alexander Weiss, Executing large orders in a microscopic market model,\n",
    "<span>http://arxiv.org/abs/0904.4131v2</span> (2009).\n",
    "  </li>\n",
    "    \n",
    "</ol>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
